package com.guli.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guli.commonutils.R;
import com.guli.edu.entity.Course;
import com.guli.edu.entity.Teacher;
import com.guli.edu.service.CourseService;
import com.guli.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: IndexFrontController 
 * @Description: TODO
 * @author: liuzg
 * @Date: 2021/3/22 11:03
 * @Version: v1.0
 */
@RestController
@RequestMapping(value = "/edu/indexfront")
@Api(tags = "前端访问首页")
public class IndexFrontController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @ApiOperation(value = "查询前8条热门课程，查询前4条名师")
    @GetMapping(value = "/index")
    public R index() {

        // 调用各个service层，用于存储redis

        //查询前8条热门课程
//        QueryWrapper<Course> wrapper = new QueryWrapper<>();
//        wrapper.orderByDesc("id");
//        wrapper.last("limit 8");
//        List<Course> eduList = courseService.list(wrapper);
        List<Course> eduList = courseService.getEduList();

        //查询前4条名师
//        QueryWrapper<Teacher> wrapperTeacher = new QueryWrapper<>();
//        wrapperTeacher.orderByDesc("id");
//        wrapperTeacher.last("limit 4");
//        List<Teacher> teacherList = teacherService.list(wrapperTeacher);
        List<Teacher> teacherList = teacherService.getTeacherList();

        return R.ok().data("eduList", eduList).data("teacherList", teacherList);
    }
}
